home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / HARDWARE / IICALARM / !iicAlarm / Tools / !AlarmShut / !Runimage (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1994-05-04  |  8KB  |  253 lines

  1.  > iicAlarmShutdown 0.50
  2.  This program shuts down the computer and switches it off.
  3.  This program was developed from !Shutdown by Stuart Hickinbottom,
  4.  thanks for the idea.
  5.  Version 0.30
  6.  It sends a <Shift-Control_F12> to the wimp and waits for the applikations
  7.  to close down. It shows a window and sets the Aux-lines to switch off
  8.  the computer.
  9.  Version 0.40
  10.  New in RiscOs 3.xx. It sends a Shutdown-Command to the TaskManager.
  11.  ESCAPE key functions as an abort key.
  12.  Version 0.50
  13.  removed all RiscOs2 stuff.
  14. +10000
  15.  ON ERROR PROCerrorReport(REPORT$,FALSE)
  16. "Error in Shutdown: ";
  17. $" in "
  18. "<AlarmShut$Dir>.^.^.SwitchOff"
  19. Dapname$ = "iicAlarmShutdown"       :
  20.  Name in Taskmanager-Window
  21.  buff% 1024                     :
  22.  Buffer for window & Template
  23. spritelen% = 10*1024
  24.  spritebuf% spritelen%          :
  25.  Buffer for Sprites
  26. indlen% = 100
  27.  indbuf% indlen%                :
  28.  Buffer for indirected Data
  29. ptr% = indbuf%
  30. status% = 0
  31. Bf% = 7                             :
  32.  Iconno. in Templatefile.
  33.  If we are in command-mode/non-desktop. We can simply call the
  34.  switch-off function.
  35.  We check it by the number of existing applications.
  36. "Wimp_ReadSysInfo", 0 
  37.  tasknum%
  38.  tasknum%<2 
  39. switchoff
  40.  Otherwise. We use a Task-program to control the shutdown procedure
  41.  of the applications.
  42.  BUT we can still be in a command-line, eg. F12-mode or task-window.
  43.  Meaning, that we have to start from within a task...
  44.  This doesn't work with Wimp_Initialise because the current task refuses
  45.  to die. Problem.. a new task can only start a *command...
  46.  Since we are run only under the desktop, we are always started via
  47.  Filer_Run or StartTask... or so.
  48. 4EAuxSet = 
  49. initSwitchOffRoutine    :
  50.  Routine to set Aux1/2-lines.
  51. 67taskhdl%=
  52. initTask(apname$)       :
  53.  Enter the Wimp
  54. getTemplate                    :
  55.  Load our window
  56. loadSprites
  57.  From now on we don't need to load anything else.
  58. displayWindow(
  59.  Now in RiscOS 3, we have a command for the taskmanager itself.
  60.  We tell him to shutdown without the dialogue box.
  61. "TaskManager_Shutdown", %00001
  62. @!mask% = %11100001100000110000
  63. status% = 2
  64. errorReport(
  65.  Wir koennen noch nicht herausfinden, ob jemand abbrechen wollte und
  66.  haben deshalb nur ein Timeout von 30 Sekunden.
  67. tm% = 
  68.  + 3000
  69. wimpPoll
  70. wimpPoll
  71. O%   
  72. "Wimp_Poll",mask%,buff% 
  73.       
  74.  0     : 
  75. NULLevent
  76. R.      
  77.  2     : 
  78. "Wimp_OpenWindow",,buff%
  79. S:      
  80.  6     : 
  81. checkMouse(buff%!8,buff%!12,buff%!16)
  82. T8      
  83.  8     : 
  84. checkKeys(buff%!0,buff%!4,buff%!24)
  85. ; Nullevents bearbeiten
  86. [L; Unser Rechner hat also genug Zeit, um sich mit sowas zu beschaeftigen.
  87. NULLevent
  88. ])   
  89. "Wimp_ReadSysInfo", 0 
  90.  tasknum%
  91.  tasknum%<2 
  92.       
  93.  status% 
  94.       
  95. 0,1: status% += 1
  96. a'      
  97.  2 : 
  98.  "XOS_CLI","ShutDown"
  99. b$               
  100. displayWindow(
  101.                status% += 1
  102.       
  103.  3 : tm% = 
  104.  + 2000
  105. eI               
  106.  Shutflag gesetzt. Also alle Tasks weg und alle Files
  107. fK               
  108.  geschlossen.Jetzt koenen wir die Aux-Leitungen setzen.
  109. g#               A% = 3: 
  110.  AuxSet
  111.                status% += 1
  112. i)               
  113. "Hourglass_Start", 1
  114. j5      
  115.  4 : 
  116. "Hourglass_Percentage", (tm%-
  117. )/100
  118.       
  119. ; Bearbeite Mouseclicks
  120. pM; Wenn unser Fenster betroffen ist und unser Icon gedrueckt wurde mit der
  121. q?; richtigen Taste dann fuehre den gewuenschten RESET durch.
  122. r6;                  buttons windowhandle iconhandle
  123. checkMouse(B%,g%,q%)
  124.      
  125. winhdl%:
  126. v3                    
  127. 2)<>2 
  128. doReset
  129.                  
  130. ; Bearbeite Tastaturevents
  131. |:; Wenn unser Fenster gemeint ist und 
  132.  gedrueckt wurde
  133. }F; dann invertieren wir unsere Taste als haetten wir sie gedrueckt.
  134. ~%; ansonsten geben wir sie weiter.
  135. 5; Wenn ESCAPE gedrueckt wird, beenden wir sofort.
  136. '; windowhandle iconhandle character
  137. checkKeys(g%,q%,r%)
  138.       
  139. winhdl%:
  140.  r%=13 
  141. (                     buff%!0=winhdl%
  142. #                     buff%!4=f%
  143. &                     buff%!8=1<<21
  144. '                     buff%!12=1<<21
  145. 5                     
  146. "Wimp_SetIconState",,buff%
  147. 2                     
  148. checkMouse(1,winhdl%,f%)
  149.                      s%=
  150.                   
  151. %                  
  152.  r%=27 
  153.  tm%=
  154. "Wimp_ProcessKey",r%
  155. displayWindow(C%)
  156.  h%,i%
  157.  Fenster auf dem Bildschirm zentrieren.
  158. getScreensize
  159.    buff%!0 = winhdl%
  160. "Wimp_GetWindowState",,buff%
  161.    h% = buff%!12 - buff%!4
  162.    i% = buff%!16 - buff%!8
  163.    buff%!4 = j%/2 - h%/2
  164.    buff%!8 = k%/2 - i%/2
  165.  buff%!4=-32000:buff%!8=-32000
  166.    buff%!12=buff%!4+h%
  167.    buff%!16=buff%!8+i%
  168.  Fenster anzeigen
  169. "Wimp_OpenWindow",,buff%
  170.  Cursor in unser Fenster, aber unsichtbar !!
  171. "Wimp_SetCaretPosition",winhdl%,-1,0,0,1<<25,0
  172. &; Berechne Bildgroesse in OSunits.
  173. getScreensize
  174.  u%,v%
  175. "OS_ReadModeVariable",
  176.  ,,u%
  177. "OS_ReadModeVariable",
  178.  ,,v%
  179. "OS_ReadModeVariable",
  180.  ,,j%
  181. "OS_ReadModeVariable",
  182.  ,,k%
  183. "   j%=(j%+1)<<u%:k%=(k%+1)<<v%
  184. doReset
  185. t% 50
  186.    P%=t%
  187.    [ OPT0
  188.         MOV     R0,#200
  189. 1        MOV     R1,#3            ; Escape aus
  190. D        MOV     R2,#0            ; Reset ergibt nun einen echten
  191. 1        SWI     "XOS_Byte"       ; Kaltstart.
  192.          MOV     R0,#&3800000
  193.         LDR     R1,[R0]
  194.         STR     R1,[R1,-1]
  195. H        SWI     "XOS_EnterOS"    ; Reset nur im Supervisor moeglich.
  196.         MOV     R0,R0
  197. 8        MOV     PC,#0            ; Reset-Ansprung !!
  198.    tm%=
  199. .; Anzeigen eines Errors in einer Errorbox.
  200. 3; Je nach Typ werden verchiedene Boxen gezeigt.
  201. 2; Wird CANCEL gewaehlt, wird abnormal beendet.
  202. errorReport(a$,D%)
  203.  Cancel Drag-Operations
  204. "Wimp_DragBox",,-1
  205. O      
  206. <>2001 
  207.  a$+=" (internal error code "+
  208. +"). Do you wish to quit?"
  209.       a$+=
  210.       d%=1-2*(
  211. <>2001)
  212.       d%=2
  213.    !buff%=
  214.    $(buff%+4)=a$
  215. "Wimp_ReportError",buff%,d%,apname$ 
  216. (d%=1
  217. <>2001) 
  218. initTask(c$)
  219.  w%,x%
  220. "Wimp_Initialise",200,&4B534154,c$ 
  221.  w%,x%
  222.  w%<200 
  223. 0,"WIMP is too old to initialise '"+c$+"'."
  224. getTemplate
  225. "Wimp_OpenTemplate",,"<AlarmShut$Dir>.Templates"
  226. 4   winhdl% = 
  227. loadWindow("AlarmShut",spritebuf%)
  228. "Wimp_CloseTemplate"
  229. loadWindow(tplname$,sprbuf%)
  230.  Wir laden das erste Window in den Speicher.
  231. "Wimp_LoadTemplate",,buff%,ptr%,indbuf%+indlen%,-1,
  232. tplname$+
  233. 0)),0 
  234.  ,,ptr%
  235.    buff%!64=sprbuf%
  236.  Wir uebergeben das Fenster ans WIMP.
  237.  Damit koennen wir unsere Daten vergessen.
  238. "Wimp_CreateWindow",,buff% 
  239. loadSprites
  240.  Sprite-Bereich vorbereiten
  241.    spritebuf%!0=spritelen%
  242.    spritebuf%!4=0
  243.    spritebuf%!8=16
  244.    spritebuf%!12=16
  245.  Sprite laden in privaten Pool
  246. "OS_SpriteOp",266,spritebuf%,"<AlarmShut$Dir>.Sprites"
  247. ); End-routine for normal termination.
  248. +; End-routine for abnormal termination.
  249.    A% = 0: 
  250.  AuxSet
  251. "Hourglass_Off"
  252. "Wimp_CloseDown",taskhdl%,&4B534154
  253.